﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data;

using CE.User;
using CE.Global;
using CE.Database;
using CE.Report;


public partial class cancel_application_report : System.Web.UI.Page
{
    string PageCode = "CXTHRCAP";
    DataTable _dtSummary = new DataTable();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session[CE.Global.General.UserId] == null)
        {
            Response.Redirect("ManagementSecureLogin.aspx");
        }
        if (!IsPostBack)
        {
            Session["Language"] = null;
            trRecordCount.Visible = false;
            lblError.Text = "";
            ddlDay1.Visible = true;
            lblFromDate.Text = "Date :";
            lblToDate.Visible = false;
            ddlDay2.Visible = false;
            ddlMonth2.Visible = false;
            ddlYear2.Visible = false;
            ddlYear1.Items.Clear();
            ddlYear2.Items.Clear();

            int _cryr = CE.Global.General.GetUTCDateTime().Year;
            int _styr = 2010;
            for (int _year = _cryr; _year >= _styr; _year--)
            {
                ddlYear1.Items.Add(new ListItem(_year.ToString(), _year.ToString()));
                ddlYear2.Items.Add(new ListItem(_year.ToString(), _year.ToString()));
            }

            ddlDay1.Text = CE.Global.General.GetUTCDateTime().Day.ToString("00");
            ddlMonth1.Text = CE.Global.General.GetUTCDateTime().Month.ToString("00");
            ddlYear1.Text = CE.Global.General.GetUTCDateTime().Year.ToString("0000");
            ddlDay2.Text = CE.Global.General.GetUTCDateTime().Day.ToString("00");
            ddlMonth2.Text = CE.Global.General.GetUTCDateTime().Month.ToString("00");
            ddlYear2.Text = CE.Global.General.GetUTCDateTime().Year.ToString("0000");
            Session[CE.Global.General.InsParam] = null;
            LoadInsurerList();
            if (Request.QueryString["ceid"] != null)
            {
                trSearch.Visible = false;
                Button1_Click(this, null);
            }
            else
            {
                trSearch.Visible = true;
            }
        }
        if (Convert.ToInt64(Session[General.UserId].ToString()) != 1)
        {
            CheckPageAccess();
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Session[CE.Global.General.InsParam] = null;
        Cache.Remove("Result");
        ViewState["SortExpression"] = "SubmitedDate";
        ViewState["SortOrder"] = " DESC";
        trRecordCount.Visible = true;
        LoadGrid();
        Session["Language"] = ddlLanguage.Text;
    }

    protected void btnExport_Click(object sender, EventArgs e)
    {
        if (grvExport.Rows.Count > 0)
        {
            string _strDateRange = "Date";
            string _ReportType = "";
            string _InsuranceType = "CI";
            string _strDate1 = txtReportDate1.Text;
            string _strDate2 = txtReportDate2.Text;
            string _Date = "";
            string _FileName = "PaymentCancelledReport@";
            if (ddlInsuranceType.Text == "All")
            {
                _InsuranceType = "All Insurances";
            }
            else if (ddlInsuranceType.Text == "CI")
            {
                _InsuranceType = "Car Insurance";
            }
            _ReportType = "";
            if (ddlReportType.Text == "0")
            {
                _ReportType = "Monthly";
                _Date = ": " + GetMonth(_strDate1.Substring(4, 2).ToString());
                _Date += " " + _strDate1.Substring(0, 4).ToString();

                _FileName += GetMonth(_strDate1.Substring(4, 2).ToString()).Trim() + _strDate1.Substring(0, 4).ToString();
            }
            else if (ddlReportType.Text == "1")
            {
                _ReportType = "Daily";
                _Date = " : " + _strDate1.Substring(6, 2).ToString();
                _Date += " " + GetMonth(_strDate1.Substring(4, 2).ToString());
                _Date += " " + _strDate1.Substring(0, 4).ToString();

                _FileName += _strDate1.Substring(6, 2).ToString() + GetMonth(_strDate1.Substring(4, 2).ToString()).Trim() + _strDate1.Substring(0, 4).ToString();
            }
            else if (ddlReportType.Text == "2")
            {
                _ReportType = "Customize";
                _Date = " : " + _strDate1.Substring(6, 2).ToString();
                _Date += " " + GetMonth(_strDate1.Substring(4, 2).ToString());
                _Date += " " + _strDate1.Substring(0, 4).ToString();
                _Date += " TO " + _strDate2.Substring(6, 2).ToString();
                _Date += " " + GetMonth(_strDate2.Substring(4, 2).ToString());
                _Date += " " + _strDate2.Substring(0, 4).ToString();

                _FileName += _strDate1.Substring(6, 2).ToString() + GetMonth(_strDate1.Substring(4, 2).ToString()).Trim() + _strDate1.Substring(0, 4).ToString();
            }
            string Campaign = "Online";
            if (ddlCampaign.Text == "1001")
            {
                Campaign = "Offline";
            }
            _strDateRange = "<tr><td>Report Type</td><td colspan='8'>: " + _ReportType + "</td></tr><tr><td>Statement Date</td><td align='left' colspan='8'>" + _Date + "</td></tr>";

            string strHeader = "<meta http-equiv='content-type' content='text/html; charset=UTF-8'>";
            strHeader += "<table><tr><td colspan='8'><h3>Payment Cancelled Application Report</h3></td>";
            strHeader += "<td style='color:white'>" + CE.Global.General.GetUTCDateTime() + "</td></tr>";
            strHeader += "<tr><td>Insurer</td><td colspan='8'>: " + CE.Global.General.GetProviderName(ddlProvider.Text) + "</td></tr>";
            strHeader += _strDateRange;
            strHeader += "<tr><td>Campaign</td><td colspan='8'>: " + Campaign + "</td></tr>";
            strHeader += "<tr><td>Record Count</td><td colspan='8'>: " + lblRecordCount.Text + "</td></tr>";
            strHeader += "<tr><td></td><td colspan='8'></td></tr>";
            strHeader += "<tr><td colspan='9'>";
            strHeader += "<span style='color:#8A0808; font-size: 14px; font-weight:bold;'>&nbsp;&nbsp;APP TYPE :&nbsp;</span>";
            strHeader += "<span style='color:#B4045F; font-size: 14px; font-weight:bold;'>&nbsp;&nbsp;NEW - New&nbsp;&nbsp;</span>|";
            strHeader += "<span style='color:#04B404; font-size: 14px; font-weight:bold;'>&nbsp;&nbsp;REN - Renewal with Same Insurer&nbsp;&nbsp;</span>|";
            strHeader += "<span style='color:#0000FF; font-size: 14px; font-weight:bold;'>&nbsp;&nbsp;RNO - Renewal with Other Insurer&nbsp;&nbsp;</span>|";
            strHeader += "<span style='color:#DF0101; font-size: 14px; font-weight:bold;'>&nbsp;&nbsp;CHB - Change from Other Broker</span>";
            strHeader += "</td></tr>";
            strHeader += "</table>";

            ExportGridView(_FileName, grvExport, strHeader);
        }
    }

    protected void ddlReportType_SelectedIndexChanged(object sender, EventArgs e)
    {
        lblError.Text = "";
        ddlDay1.Text = CE.Global.General.GetUTCDateTime().Day.ToString("00");
        ddlDay2.Text = CE.Global.General.GetUTCDateTime().Day.ToString("00");
        ddlMonth1.Text = CE.Global.General.GetUTCDateTime().Month.ToString("00");
        ddlMonth2.Text = CE.Global.General.GetUTCDateTime().Month.ToString("00");
        ddlYear1.Text = CE.Global.General.GetUTCDateTime().Year.ToString("0000");
        ddlYear2.Text = CE.Global.General.GetUTCDateTime().Year.ToString("0000");
        if (Convert.ToInt16(ddlReportType.Text) == 0)
        {
            ddlDay1.Visible = false;
            lblFromDate.Text = "Date :";
            lblToDate.Visible = false;
            ddlDay2.Visible = false;
            ddlMonth2.Visible = false;
            ddlYear2.Visible = false;
        }
        else if (Convert.ToInt16(ddlReportType.Text) == 1)
        {
            ddlDay1.Visible = true;
            lblFromDate.Text = "Date :";
            lblToDate.Visible = false;
            ddlDay2.Visible = false;
            ddlMonth2.Visible = false;
            ddlYear2.Visible = false;
        }
        else if (Convert.ToInt16(ddlReportType.Text) == 2)
        {
            lblFromDate.Text = "From Date :";
            lblToDate.Text = " To Date :";
            lblToDate.Visible = true;
            ddlDay2.Visible = true;
            ddlMonth2.Visible = true;
            ddlYear2.Visible = true;
            ddlDay1.Visible = true;
        }
    }

    protected void grvProposalSummary_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
            if (Session[CE.Global.General.UserRole] != null && Session[CE.Global.General.UserRole].ToString() == "300")
            {
                e.Row.Cells[2].Visible = true;
                e.Row.Cells[3].Visible = false;
            }
            else
            {
                e.Row.Cells[2].Visible = false;
                e.Row.Cells[3].Visible = true;
            }
        }
        //Int64 PageAccess = General.GetPageAccess(Convert.ToInt64(Session[General.UserId].ToString()), PageCode);
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (Session[CE.Global.General.UserRole] != null && Session[CE.Global.General.UserRole].ToString() == "300")
            {
                e.Row.Cells[2].Visible = true;
                e.Row.Cells[3].Visible = false;
            }
            else
            {
                e.Row.Cells[2].Visible = false;
                e.Row.Cells[3].Visible = true;
            }
            //ImageButton ibtnDownload = new ImageButton();
            //ibtnDownload = (ImageButton)e.Row.FindControl("ibtnDownload");
            //if (PageAccess == 400)
            //{
            //    ibtnDownload.Enabled = true;
            //}
            //else
            //{
            //    ibtnDownload.Enabled = false;
            //}
            //if (Convert.ToInt64(Session[General.UserId].ToString()) == 1)
            //{
            //    ibtnDownload.Enabled = true;
            //}
        }
        //Boolean _DownLoadStatus = CheckDownloadAccess();
        //if (e.Row.RowType == DataControlRowType.DataRow)
        //{
        //    ImageButton ibtnDownload = new ImageButton();
        //    ibtnDownload = (ImageButton)e.Row.FindControl("ibtnDownload");
        //    if (_DownLoadStatus == true)
        //    {
        //        ibtnDownload.Enabled = true;
        //    }
        //    else
        //    {
        //        ibtnDownload.Enabled = false;
        //    }
        //}
    }

    protected void grvProposalSummary_Sorting(object sender, GridViewSortEventArgs e)
    {
        SortGridViews(e.SortExpression);
    }

    protected void grvExport_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
            if (Session[CE.Global.General.UserRole] != null && Session[CE.Global.General.UserRole].ToString() == "300")
            {
                e.Row.Cells[2].Visible = true;
                e.Row.Cells[3].Visible = false;
            }
            else
            {
                e.Row.Cells[2].Visible = false;
                e.Row.Cells[3].Visible = true;
            }
        }
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (Session[CE.Global.General.UserRole] != null && Session[CE.Global.General.UserRole].ToString() == "300")
            {
                e.Row.Cells[2].Visible = true;
                e.Row.Cells[3].Visible = false;
            }
            else
            {
                e.Row.Cells[2].Visible = false;
                e.Row.Cells[3].Visible = true;
            }
        }
    }

    public string GetReferenceNumber(string Number, string ProviderId, string InsType)
    {
        string convertno = CE.Global.General.GetRefNumber(Convert.ToInt64(Number.ToString()));
        string _RefNo = "";
        if (ProviderId == "11")
        {
            _RefNo = "AZC" + convertno.ToString();
        }
        else if (ProviderId == "12")
        {
            _RefNo = "MSI" + convertno.ToString();
        }
        else if (ProviderId == "16")
        {
            _RefNo = "AXA" + convertno.ToString();
        }
        else if (ProviderId == "29")
        {
            _RefNo = "LMG" + convertno.ToString();
        }
        else if (ProviderId == "31")
        {
            _RefNo = "CTS" + convertno.ToString();
        }
        else if (ProviderId == "32")
        {
            _RefNo = "BKI" + convertno.ToString();
        }
        else if (ProviderId == "33")
        {
            _RefNo = "MTI" + convertno.ToString();
        }
        else if (ProviderId == "35")
        {
            _RefNo = "KPI" + convertno.ToString();
        }
        else if (ProviderId == "39")
        {
            _RefNo = "MIR" + convertno.ToString();
        }
        else if (ProviderId == "41")
        {
            _RefNo = "KSK" + convertno.ToString();
        }
        else if (ProviderId == "43")
        {
            _RefNo = "SMK" + convertno.ToString();
        }
        else if (ProviderId == "45")
        {
            _RefNo = "VRY" + convertno.ToString();
        }
        else if (ProviderId == "46")
        {
            _RefNo = "TMS" + convertno.ToString();
        }
        else if (ProviderId == "50")
        {
            _RefNo = "SCS" + convertno.ToString();
        }
        else if (ProviderId == "58")
        {
            _RefNo = "TVV" + convertno.ToString();
        }
        return _RefNo;
    }

    public void ExportGridView(string fileName, GridView gvExport, string headerText)
    {
        string attachment = "attachment; filename=" + fileName + ".xls";
        Response.ClearContent();
        Response.AddHeader("content-disposition", attachment);
        Response.ContentType = "application/ms-excel";
        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);
        // Create a form to contain the grid
        HtmlForm frm = new HtmlForm();
        frm.InnerHtml = headerText;
        gvExport.Parent.Controls.Add(frm);
        frm.Attributes["runat"] = "server";
        frm.Controls.Add(gvExport);
        frm.RenderControl(htw);
        Response.Write(sw.ToString());
        Response.End();
    }

    public bool ValidDate(Int32 Year, Int32 Month, Int32 Day)
    {
        bool _isValid = true;
        int daysInMonth = 0;
        string leap, monthValid, dayValid, yearValid;
        if (Year >= 0000)
        {
            yearValid = "yes";
        }
        else
        {
            yearValid = "no";
        }
        if (Year % 400 == 0)
        {
            leap = "yes";
        }
        else if (Year % 100 == 0)
        {
            leap = "no";
        }
        else if (Year % 4 == 0)
        {
            leap = "yes";
        }
        else
        {
            leap = "no";
        }

        switch (Month)
        {
            case 1: daysInMonth = 31;
                break;
            case 3: daysInMonth = 31;
                break;
            case 4: daysInMonth = 30;
                break;
            case 5: daysInMonth = 31;
                break;
            case 6: daysInMonth = 30;
                break;
            case 7: daysInMonth = 31;
                break;
            case 8: daysInMonth = 31;
                break;
            case 9: daysInMonth = 30;
                break;
            case 10: daysInMonth = 31;
                break;
            case 11: daysInMonth = 30;
                break;
            case 12: daysInMonth = 31;
                break;
        }

        if (Month >= 1 && Month <= 12)
        {
            monthValid = "yes";
        }
        else
        {
            monthValid = "no";
        }
        if (Month == 2)
        {
            if (leap == "no")
            {
                daysInMonth = 28;
            }
            else if (leap == "yes")
            {
                daysInMonth = 29;
            }
        }

        if (1 <= Day && Day <= daysInMonth)
        {
            dayValid = "yes";
        }

        else
        {
            dayValid = "no";
        }

        if ((dayValid == "yes") && (monthValid == "yes") && (yearValid == "yes"))
        {
            _isValid = true;
        }
        else
        {
            _isValid = false;
        }

        return _isValid;
    }

    private void SortGridViews(string strExpression)
    {
        LoadGrid();
        if (ViewState["SortOrder"] == null)
        {
            ViewState["SortOrder"] = " DESC";
        }

        if (ViewState["SortExpression"] == null)
        {
            ViewState["SortExpression"] = " ASC";
        }

        DataView dv = new DataView((DataTable)_dtSummary);
        string strSort = "";
        if (ViewState["SortOrder"].ToString() == " ASC")
        {
            if (ViewState["SortExpression"].ToString() == strExpression)
            {
                strSort = " DESC";
                ViewState["SortOrder"] = " DESC";
                ViewState["SortExpression"] = strExpression;
            }
            else
            {
                strSort = " ASC";
                ViewState["SortOrder"] = " ASC";
                ViewState["SortExpression"] = strExpression;
            }

        }
        else
        {
            if (ViewState["SortExpression"].ToString() == strExpression)
            {
                strSort = " ASC";
                ViewState["SortOrder"] = " ASC";
                ViewState["SortExpression"] = strExpression;
            }
            else
            {
                strSort = " DESC";
                ViewState["SortOrder"] = " DESC";
                ViewState["SortExpression"] = strExpression;
            }

        }

        dv.Sort = strExpression + strSort;
        grvProposalSummary.DataSource = dv;
        grvProposalSummary.DataBind();

        grvExport.DataSource = dv;
        grvExport.DataBind();
    }

    public string GetDownloadURl(string refid)
    {
        string _url = "";
        string _refId = CE.Security.MySecurity.Encrypt(refid.ToString(), true);
        _url = "javascript:OpenProposal('" + refid.ToString() + "');";
        return _url;
    }

    public string GetMonth(string month)
    {
        string result = "";
        if (month == "01")
        {
            result = " Jan ";
        }
        else if (month == "02")
        {
            result = " Feb ";
        }
        else if (month == "03")
        {
            result = " Mar ";
        }
        else if (month == "04")
        {
            result = " Apr ";
        }
        else if (month == "05")
        {
            result = " May ";
        }
        else if (month == "06")
        {
            result = " Jun ";
        }
        else if (month == "07")
        {
            result = " Jul ";
        }
        else if (month == "08")
        {
            result = " Aug ";
        }
        else if (month == "09")
        {
            result = " Sep ";
        }
        else if (month == "10")
        {
            result = " Oct ";
        }
        else if (month == "11")
        {
            result = " Nov ";
        }
        else if (month == "12")
        {
            result = " Dec ";
        }
        return result;
    }

    public bool Validatioin()
    {
        lblError.Text = "";
        bool _isValid = true;
        DateTime _fromDate, _toDate;
        if (Convert.ToInt16(ddlReportType.Text) == 1)
        {
            if (ddlDay1.SelectedIndex >= 0)
            {
                if (ValidDate(Convert.ToInt32(ddlYear1.Text), Convert.ToInt32(ddlMonth1.Text), Convert.ToInt32(ddlDay1.Text)))
                {
                    _fromDate = Convert.ToDateTime(Convert.ToInt32(ddlYear1.Text) + "/" + Convert.ToInt32(ddlMonth1.Text) + "/" + Convert.ToInt32(ddlDay1.Text));
                    if (_fromDate > CE.Global.General.GetUTCDateTime())
                    {
                        _isValid = false;
                        lblError.Text = "Date should be less than or equal to Today";
                    }
                }
                else
                {
                    _isValid = false;
                    lblError.Text = "Select Valid Date";
                }
            }
            else
            {
                _isValid = false;
                lblError.Text = "Select Date";
            }
        }
        else if (Convert.ToInt16(ddlReportType.Text) == 2)
        {
            if (ddlDay1.SelectedIndex >= 0 && ddlDay2.SelectedIndex >= 0)
            {
                if (ValidDate(Convert.ToInt32(ddlYear1.Text), Convert.ToInt32(ddlMonth1.Text), Convert.ToInt32(ddlDay1.Text)))
                {
                    _fromDate = Convert.ToDateTime(Convert.ToInt32(ddlYear1.Text) + "/" + Convert.ToInt32(ddlMonth1.Text) + "/" + Convert.ToInt32(ddlDay1.Text));
                    if (ValidDate(Convert.ToInt32(ddlYear2.Text), Convert.ToInt32(ddlMonth2.Text), Convert.ToInt32(ddlDay2.Text)))
                    {
                        _toDate = Convert.ToDateTime(Convert.ToInt32(ddlYear2.Text) + "/" + Convert.ToInt32(ddlMonth2.Text) + "/" + Convert.ToInt32(ddlDay2.Text));
                        if (_fromDate <= CE.Global.General.GetUTCDateTime())
                        {
                            if (_fromDate > _toDate)
                            {
                                _isValid = false;
                                lblError.Text = "From date should be less than To date";
                            }
                        }
                        else
                        {
                            _isValid = false;
                            lblError.Text = "From date should be less than Today";
                        }
                    }
                    else
                    {
                        _isValid = false;
                        lblError.Text = "Select Valid To date";
                    }
                }
                else
                {
                    _isValid = false;
                    lblError.Text = "Select Valid From date";
                }
            }
            else
            {
                _isValid = false;
                lblError.Text = "Select From date and To date";
            }
        }
        return _isValid;
    }

    public void LoadGrid()
    {
        divLegend.Visible = false;
        lblError.Text = "";
        if (Validatioin() == true)
        {
            if (Request.QueryString["ceid"] != null)
            {
                txtCEID.Text = Request.QueryString["ceid"].ToString();
            }
            else
            {
                txtCEID.Text = "0";
            }
            if (Request.QueryString["instype"] != null)
            {
                ddlInsuranceType.Text = Request.QueryString["instype"].ToString();
            }
            txtReportDate1.Text = "";
            txtReportDate2.Text = CE.Global.General.GetUTCDateTime().Year.ToString("0000") + CE.Global.General.GetUTCDateTime().Month.ToString("00") + CE.Global.General.GetUTCDateTime().Day.ToString("00");
            txtReportDate1.Text = ddlYear1.Text;
            txtReportDate1.Text += ddlMonth1.Text;
            if (ddlReportType.SelectedIndex > 0)
            {
                if (ddlDay1.SelectedIndex >= 0)
                {
                    txtReportDate1.Text += ddlDay1.Text;
                }
            }
            if (ddlReportType.SelectedIndex == 2)
            {
                txtReportDate2.Text = ddlYear2.Text;
                txtReportDate2.Text += ddlMonth2.Text;
                txtReportDate2.Text += ddlDay2.Text;
            }
            ProposalSummary _proposalsummary = new ProposalSummary();
            ProposalSummaryDB _proposalsummarydb = new ProposalSummaryDB();
            Session[CE.Global.General.InsParam] = null;
            Int64 _ProviderId = Convert.ToInt16(ddlProvider.Text);
            Int16 _AppStatus = 2;
            Int16 _InsuranceType = Convert.ToInt16(ddlInsuranceType.Text);
            string _ApplicationType = ddlApplicationType.Text;
            Int16 _ReportType = Convert.ToInt16(ddlReportType.Text);
            string _ReportDate1 = txtReportDate1.Text.Trim();
            string _ReportDate2 = txtReportDate2.Text.Trim();
            string _RefCEUserId = Session[CE.Global.General.UserId].ToString();
            Int64 _CurrentUserId = Convert.ToInt64(txtCEID.Text.Trim());
            Int32 _UserTypeId = Convert.ToInt32(ddlCampaign.Text);
            Session[CE.Global.General.InsParam] = _ProviderId + "," + _InsuranceType + "," + _ReportType + "," + _ReportDate1 + "," + _ReportDate2 + "," + _CurrentUserId + "," + _AppStatus + "," + _ApplicationType + "," + _UserTypeId;
            _dtSummary = _proposalsummarydb.GetNonGGApplicationSummary(_ProviderId, _InsuranceType, _ApplicationType, _ReportType, _ReportDate1, _ReportDate2, _AppStatus, _CurrentUserId, _UserTypeId);
            if (_dtSummary != null && _dtSummary.Rows.Count > 0)
            {
                lblError.Text = "";
                divLegend.Visible = true;
                //Cache["Result"] = _dtSummary;
                DataView dv = new DataView((DataTable)_dtSummary);
                dv.Sort = ViewState["SortExpression"].ToString() + ViewState["SortOrder"].ToString();
                grvProposalSummary.DataSource = dv;
                grvProposalSummary.DataBind();

                grvExport.DataSource = dv;
                grvExport.DataBind();
                lblRecordCount.Text = grvExport.Rows.Count.ToString() + " record(s).";
            }
            else
            {
                divLegend.Visible = false;
                grvProposalSummary.DataSource = null;
                grvProposalSummary.DataBind();

                grvExport.DataSource = null;
                grvExport.DataBind();
                lblRecordCount.Text = "";
            }
        }
        else
        {
            divLegend.Visible = false;
            grvProposalSummary.DataSource = null;
            grvProposalSummary.DataBind();

            grvExport.DataSource = null;
            grvExport.DataBind();
            lblRecordCount.Text = "";
        }
        if (grvProposalSummary.Rows.Count > 0)
        {
            hplPrint.NavigateUrl = "~/pendingapplication_printpreview.aspx";
            //hplPrint.Visible = true;
            hplPrint.Visible = false;
            btnExport.Visible = true;
        }
        else
        {
            hplPrint.NavigateUrl = "";
            hplPrint.Visible = false;
            btnExport.Visible = false;
        }
    }

    private void CheckPageAccess()
    {
        Int64 PageAccess = General.GetPageAccess(Convert.ToInt64(Session[General.UserId].ToString()), PageCode);
        if (PageAccess == 0)
        {
            Response.Redirect("UserMessage.aspx?menu=0&mt=UM&ec=101");
        }
        else
        {
            EnablePageAccess(PageAccess);
        }
    }

    private void EnablePageAccess(Int64 PageAccess)
    {
        if (PageAccess == 100)
        {
            btnExport.Enabled = false;
        }
        else if (PageAccess == 200)
        {
            btnExport.Enabled = true;
        }
    }

    private bool CheckDownloadAccess()
    {
        Boolean _download = false;
        Int64 PageAccess = General.GetPageAccess(Convert.ToInt64(Session[General.UserId].ToString()), PageCode);
        if (PageAccess == 400)
        {
            _download = true;
        }
        return _download;
    }

    private void LoadInsurerList()
    {
        try
        {
            MyDatabase _db = new MyDatabase("GGR_DBConnectionString");
            DataTable _dt = new DataTable("tblInsurer");
            string _spName = "sprocReportsProviderCompanySelectedList";

            _dt = _db.GetDataTable(_spName);
            ddlProvider.Items.Clear();
            if (_dt != null && _dt.Rows.Count > 0)
            {
                ddlProvider.DataSource = _dt;
                ddlProvider.DataTextField = "CompanyName";
                ddlProvider.DataValueField = "ProviderCompanyId";
                ddlProvider.DataBind();
                ddlProvider.Items.Insert(0, new ListItem("All", "0"));
            }
        }
        catch (Exception Ex)
        {
        }
    }

}
